<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 数字 转 布尔，除了 0 和 NaN 为false, 其余都是true
        var a = 123; //true
        a = -123; //true
        a = 0; //false
        a = Infinity; // true
        a = NaN; // false
        a = Boolean(a);
        console.log(typeof a);
        console.log(a);
        // 字符串除了空串，其余都是true
        var b = "false"; //true
        b = " "; // true
        b = ""; // false
        b = Boolean(b);
        console.log(typeof b);
        console.log(b);
        // null 和 undefined 都是false
    </script>
</body>

</html>